package com.dxtx.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ListView;

import com.dxtx.common.R;


/**
 * Created by user on 2016/5/19.
 */
public class AnimListView extends ListView {
    public AnimListView(Context context) {
        super(context);
    }

    public AnimListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AnimListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void postEnterWithAnim() {
        getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
                for (int i = 0; i < getChildCount(); i++) {
                    Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.enter_from_left);
                    animation.setDuration(i * 300 + 300);
                    animation.setInterpolator(new LinearInterpolator());
                    getChildAt(i).startAnimation(animation);
                }
            }
        });
    }


}
